package com.zmj.sy.mom.srv.aps.service;

import com.zmj.sy.mom.srv.aps.bean.entity.resource.Group;
import com.zmj.sy.mom.srv.aps.bean.entity.resource.Station;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseIdReqVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseListResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.stationgroup.*;
import com.zmj.sy.mom.srv.aps.mapper.GroupMapper;
import com.zmj.sy.mom.srv.aps.mapper.StationMapper;
import com.zmj.sy.mom.srv.aps.utils.SyExceptionUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Service
public class StationGroupService {

    private final GroupMapper groupMapper;
    private final StationMapper stationMapper;

    public BaseListResVo<StationGroupListResVo> list(BaseIdReqVo reqVo) {
//        LambdaQueryWrapper<StationGroup> wrapper = Wrappers.lambdaQuery();
//        wrapper.eq(StationGroup::getGroupId, reqVo.getId());
//        List<StationGroup> stationGroups = stationGroupMapper.selectList(wrapper);
//        return BaseListResVo.of(stationGroups, StationGroupListResVo.class);
        return BaseListResVo.empty();
    }

    @Transactional
    public void add(StationGroupAddReqVo reqVo) {

        if(reqVo.getStationId() == null){
            throw SyExceptionUtils.e("请选择工位");
        }

//        LambdaQueryWrapper<StationGroup> wrapper = Wrappers.lambdaQuery();
//        wrapper.eq(StationGroup::getGroupId, reqVo.getGroupId());
//        wrapper.eq(StationGroup::getStationId, reqVo.getStationId());
//        Integer i = stationGroupMapper.selectCount(wrapper);
//        if(i > 0) {
//            throw SyExceptionUtils.e("工作组下已经存在该工位");
//        }

//        StationGroup stationGroup = MkBeanUtils.copyProperties(reqVo, StationGroup.class);
//        stationGroupMapper.insert(stationGroup);

        return;
    }

    @Transactional
    public void edit(StationGroupEditReqVo reqVo) {
//        StationGroup stationGroup = stationGroupMapper.selectById(reqVo.getId());
//        MkBeanUtils.copyPropertiesIgnore(reqVo, stationGroup);
//        stationGroupMapper.updateById(stationGroup);
        return;
    }

    @Transactional
    public void delete(BaseIdReqVo reqVo) {
//        stationGroupMapper.deleteById(reqVo.getId());
        return;
    }

    @Transactional(readOnly = true)
    public BaseListResVo<StationGroupTreeResVo> tree() {

        return null;
    }

    public void changeStorageGroup(GroupChangeDto dto) {
        Group group = groupMapper.lambdaQuery().eq(Group::getMyCode, dto.getGroupNumber()).one();
        Station station = stationMapper.lambdaQuery().eq(Station::getMyCode, dto.getWorkNumber()).one();
//        StationGroup one = stationGroupMapper.lambdaQuery().eq(StationGroup::getStationId, station.getId()).one();
//        one.setGroupId(group.getId());
//        stationGroupMapper.updateById(one);
        return;
    }

}
